(define-module (luhux services vpn)
  #:use-module (gnu services)
  #:use-module (gnu packages)
  #:use-module (gnu packages vpn)
  #:use-module (gnu services shepherd)
  #:use-module (guix records)
  #:use-module (guix gexp)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:export (
	    wireguard-quick-service-type
	    wireguard-quick-configuration
	    )
  )

;;
;;
;;  提供VPN服务
;;
;;


(define-record-type* <wireguard-quick-configuration>
  wireguard-quick-configuration make-wireguard-quick-configuration
  wireguard-quick-configuration?
  (interface wireguard-quick-configuration-interface) ;; string
)


;; 提供wg-quick服务
(define wireguard-quick-service-type
  (shepherd-service-type
   'wireguard-quick
   (lambda (config)
     (define interface (wireguard-quick-configuration-interface config))
     (define start-command (list (file-append wireguard-tools "/bin/wg-quick") "up"
				 interface))
     (define stop-command (list (file-append wireguard-tools "/bin/wg-quick") "down"
				interface))
     (shepherd-service
      (documentation "wg-quick start/stop interface")
      (provision (list (symbol-append 'wireguard-quick- (string->symbol interface))))
      (start #~(make-forkexec-constructor '#$start-command))
      (stop #~(make-forkexec-constructor '#$stop-command))
      (one-shot? #t)
      )
     )
   )
  )
